package cn.lutu.domain.repository.impl;

import cn.lutu.dao.mapper.SpotMapper;
import cn.lutu.dao.mapper.SpotTicketMapper;
import cn.lutu.domain.repository.SpotRepository;
import cn.lutu.protocol.entity.Spot;
import cn.lutu.protocol.entity.SpotAndTicket;
import cn.lutu.protocol.entity.UserAndRole;
import cn.lutu.protocol.vo.RouteVO;
import cn.lutu.protocol.vo.SpotVO;
import cn.lutu.protocol.vo.VoteVO;
import cn.lutu.util.common.PageInfoToPageDataConverter;
import cn.lutu.util.pojo.vo.PageData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
@Slf4j
public class SpotRepositoryImpl implements SpotRepository {
    @Autowired
    SpotMapper spotMapper;

    @Autowired
    SpotTicketMapper spotTicketMapper;

    @Override
    public PageData<SpotVO> selectSpotList(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询景区列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<SpotVO> list = spotMapper.selectSpotList();
        PageInfo<SpotVO> pageInfo = new PageInfo<>(list);
        PageData<SpotVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public SpotVO selectSpotListById(Long id) {
        return spotMapper.selectSpotListById(id);
    }

    @Override
    public List<VoteVO> selectVoteById(Long id) {
        return spotMapper.selectVoteById(id);
    }
    @Override
    public int deleteSpotById(Long id) {
        log.debug("开始执行【根据删除景点信息】，参数：{}", id);
        return spotMapper.deleteById(id);
    }
    @Override
    public int addSpot(Spot spot) {
        log.debug("开始执行【新增景点数据】，参数：{}", spot);
        return spotMapper.insert(spot);
    }

    @Override
    public List<SpotVO> selectAllList() {
        log.debug("查询景区列表");
        return spotMapper.selectAllList();
    }

    @Override
    public List<SpotVO> selectIndex() {
        log.debug("查询热门经典");
        return spotMapper.selectIndex();
    }


    @Override
    public int addSpotTicket(SpotAndTicket spotAndTicket) {
        log.debug("开始执行【新增景点门票数据】，参数：{}", spotAndTicket);
        return spotTicketMapper.insert(spotAndTicket);
    }

}
